# http://www.swig.org/Doc2.0/SWIGDocumentation.html#Introduction_build_system
FIND_PACKAGE(SWIG REQUIRED)
INCLUDE(${SWIG_USE_FILE})

FIND_PACKAGE(PythonLibs)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})

SET(SWIG_SRC hellotool.i)
SET(MODULE_NAME hellotool)
SET_SOURCE_FILES_PROPERTIES(${SWIG_SRC} PROPERTIES CPLUSPLUS ON)

SWIG_ADD_LIBRARY(${MODULE_NAME} TYPE MODULE LANGUAGE python SOURCES ${SWIG_SRC})
SWIG_LINK_LIBRARIES(${MODULE_NAME} ${PYTHON_LIBRARIES} ${PROJECT_NAME})

ADD_CUSTOM_TARGET(testpy2
    COMMAND py.test --version > /dev/null && py.test -vs ../../test || true)
ADD_CUSTOM_TARGET(testpy3
    COMMAND py.test-3 --version > /dev/null && py.test-3 -vs ../../test || true)

EXECUTE_PROCESS(COMMAND python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"
    OUTPUT_VARIABLE PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE)
SET(PYTHON_INSTALL_FILES ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}.py
    ${CMAKE_CURRENT_BINARY_DIR}/_${MODULE_NAME}.so)
INSTALL(FILES hello.py DESTINATION bin)
INSTALL(FILES ${PYTHON_INSTALL_FILES} DESTINATION py_package)
INSTALL(FILES ${PYTHON_INSTALL_FILES} DESTINATION ${PYTHON_SITE_PACKAGES})

